﻿using System;
using System.Globalization;
using System.Windows.Data;
namespace CoreModule.Converters
{
    /// <summary>
    /// Tick 定位
    /// </summary>
    public class TickPositionConverter : IValueConverter
    {
        /// <summary>
        /// 
        /// </summary>
        public double SourceBegin { get; set; } = 40;
        /// <summary>
        /// 
        /// </summary>
        public double SourceEnd { get; set; } = 180;
        /// <summary>
        /// 
        /// </summary>
        /// <param name="value"></param>
        /// <param name="targetType"></param>
        /// <param name="parameter"></param>
        /// <param name="culture"></param>
        /// <returns></returns>
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            var tickValue = double.Parse(parameter.ToString());
            if (tickValue < SourceBegin)
            {
                tickValue = SourceBegin;
            }
            if (tickValue > SourceEnd)
            {
                tickValue = SourceEnd;
            }
            return (tickValue - SourceBegin) * (double)value / (SourceEnd - SourceBegin);
        }
        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            return 0;
        }
    }
}
